function addCategory1(){
	var category1Name = $('#category1Name').attr('value');
	var pageShow = 0;
    $('#category1Name').val('');
	if(category1Name==''){
		alert('一级类别名不能为空');
		return;
	}

	if($("#check_addCategory1Id").attr("checked")){
		pageShow = 1;
	};
	//$('#addCategory1Id').val('处理中..');
	$("#addCategory1Id").attr({"disabled":"disabled"});
	
	$.ajax({
		type:"POST",
		url:"categoryAjax_addCategory1.action",
		dataType:"json",
		data:{category1Name:category1Name, pageShow:pageShow},
		success:function(msg){
			var data = eval("("+msg+")"); 
			var responseCode = data.responseCode;
			var responseContent = data.responseContent;
			var category1Name = data.category1Name;
			var category1Id = data.category1Id;
			if(responseCode==0){
				alert(responseContent);
				$("#addCategory1Id").removeAttr("disabled"); 
				return ;
			}
			
			$('#category1Select').get(0).options.add(new Option(category1Name,category1Id));
			//$('#category2Select').append(new Option('yyyyyyy','1',true,true));
			//$('#category2Select').append("<option value="+category2Id+">"+category2Name+"</option>");
			$("#addCategory1Id").removeAttr("disabled"); 
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错');
			$("#addCategory1Id").removeAttr("disabled"); 
		}
	})
}


function addCategory2(){
	var category2Name = $('#category2Name').attr('value');
	var category1Id = $('#category1Select').attr('value');
	var pageShow = 0;
    $('#category2Name').val('');
	if(category1Id=='' || category1Id=='0'){
		alert('请选择一级类别');
		return;
	}
	if(category2Name==''){
		alert('二级类别名不能为空');
		return;
	}
	$("#addCategory2Id").attr({"disabled":"disabled"});
	
	if($("#check_addCategory2Id").attr("checked")){
		pageShow = 1;
	};
	
	$.ajax({
		type:"POST",
		url:"categoryAjax_addCategory2.action",
		dataType:"json",
		data:{category2Name:category2Name,category1Id:category1Id, pageShow:pageShow},
		success:function(msg){
			var data = eval("("+msg+")"); 
			var responseCode = data.responseCode;
			var responseContent = data.responseContent;
			var category2Name = data.category2Name;
			var category2Id = data.category2Id;
			if(responseCode==0){
				alert(responseContent);
				$("#addCategory2Id").removeAttr("disabled");
				return ;
			}
			$('#category2Select').get(0).options.add(new Option(category2Name,category2Id));
			//$('#category2Select').append(new Option('yyyyyyy','1',true,true));
			//$('#category2Select').append("<option value="+category2Id+">"+category2Name+"</option>");
			$("#addCategory2Id").removeAttr("disabled");
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错');
			$("#addCategory2Id").removeAttr("disabled");
		}
	})
}

function addCategory3(){
	var category3Name = $('#category3Name').attr('value');
	var category2Id = $('#category2Select').attr('value');
	$('#category3Name').val('');
	if(category2Id=='' || category2Id=='0'){
		alert('请选择二级类别');
		return;
	}
	if(category3Name==''){
		alert('三级类别名不能为空');
		return;
	}
	$("#addCategory3Id").attr({"disabled":"disabled"});
	$.ajax({
		type:"POST",
		url:"categoryAjax_addCategory3.action",
		dataType:"json",
		data:{category3Name:category3Name,category2Id:category2Id},
		success:function(msg){
			var data = eval("("+msg+")"); 
			var responseCode = data.responseCode;
			var responseContent = data.responseContent;
			var category3Name = data.category3Name;
			var category3Id = data.category3Id;
			if(responseCode==0){
				alert(responseContent);
				$("#addCategory3Id").removeAttr("disabled");
				return ;
			}
			$('#category3Select').get(0).options.add(new Option(category3Name,category3Id));
			$("#addCategory3Id").removeAttr("disabled");
		},
		error:function(er){
			alert('系统出错');
			$("#addCategory3Id").removeAttr("disabled");
		}
	})
}

function addPropertyType(){
	var propertyTypeName = $('#propertyTypeName').attr('value');
	var category3Id = $('#category3Select').attr('value');
	$('#propertyTypeName').val('');
	if(category3Id=='' || category3Id=='0'){
		alert('请选择三级类别');
		return;
	}
	if(propertyTypeName==''){
		alert('属性类型名不能为空');
		return;
	}
	$.ajax({
		type:"POST",
		url:"categoryAjax_addProductPropertyType.action",
		dataType:"json",
		data:{propertyTypeName:propertyTypeName,category3Id:category3Id},
		success:function(msg){
			var data = eval("("+msg+")"); 
			var responseCode = data.responseCode;
			var responseContent = data.responseContent;
			var propertyTypeName = data.propertyTypeName;
			var propertyTypeId = data.propertyTypeId;
			if(responseCode==0){
				alert(responseContent);
				return ;
			}
			$('#propertyTypeSelect').get(0).options.add(new Option(propertyTypeName,propertyTypeId));
		},
		error:function(er){
			alert(er.responseText);
			alert('系统出错');
		}
	})
}

function addPropertyValue(){
	var propertyValueName = $('#propertyValueName').attr('value');
	var propertyTypeId = $('#propertyTypeSelect').attr('value');
	$('#propertyValueName').val('');
	if(propertyTypeId=='' || propertyTypeId=='0'){
		alert('请选择属性类型');
		return;
	}
	if(propertyValueName==''){
		alert('属性值不能为空');
		return;
	}
	$.ajax({
		type:"POST",
		url:"categoryAjax_addProductPropertyValue.action",
		dataType:"json",
		data:{propertyValueName:propertyValueName,propertyTypeId:propertyTypeId},
		success:function(msg){
			var data = eval("("+msg+")"); 
			var responseCode = data.responseCode;
			var responseContent = data.responseContent;
			var propertyValueName = data.propertyValueName;
			var propertyValueId = data.propertyValueId;
			if(responseCode==0){
				alert(responseContent);
				return ;
			}
			$('#propertyValueSelect').get(0).options.add(new Option(propertyValueName,propertyValueId));
		},
		error:function(er){
			alert('系统出错');
		}
	})
}
function queryCategory2ByCategory1(){
	var params={
		category1Id:$('#category1Select').attr('value')
	};
	
	var pageShow = 0;
	$("#category1NameModify").val($('#category1Select').getSelectedText());
	
	//$("#category1NameModify").val(${categoryDtoList.categoryName});
	//alert([${categoryDtoList[1].categoryName}]);
//	if(pageShow ==1){
//		$("#check_modifyCategory1Id").attr("checked", true); 
//	}
//	if(pageShow ==0){
//		$("#check_modifyCategory1Id").attr("checked", false); 
//	}
	$.ajax({
		type:"POST",
		url:"categoryAjax_queryCategory2ByCategory1.action",
		dataType:"json",
		data:params,
		success:function(msg){
			$('#category2Select').get(0).options.length=0;
			$('#category3Select').get(0).options.length=0;
			$('#propertyTypeSelect').get(0).options.length=0;
			$('#propertyValueSelect').get(0).options.length=0;
			
			var data = eval("("+msg+")"); 
			$.each(data,function(index,data){
				var category2Id = data.id;
				var category2Name = data.categoryName;
				$('#category2Select').get(0).options.add(new Option(category2Name,category2Id));
				//$('#category2Select').append("<option value="+category2Id+">"+category2Name+"</option>");
			});
			//alert(msg.result);
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}

function queryCategory3ByCategory2(){
	var params={
		category2Id:$('#category2Select').attr('value')
	};

	//set data to modify textfield
	$("#category2NameModify").val($('#category2Select').getSelectedText());
	
	$.ajax({
		type:"POST",
		url:"categoryAjax_queryCategory3ByCategory2.action",
		dataType:"json",
		data:params,
		success:function(msg){
			$('#category3Select').get(0).options.length=0;
			$('#propertyTypeSelect').get(0).options.length=0;
			$('#propertyValueSelect').get(0).options.length=0;
			var data = eval("("+msg+")"); 
			$.each(data,function(index,data){
				var category3Id = data.id;
				var category3Name = data.categoryName;
				$('#category3Select').get(0).options.add(new Option(category3Name,category3Id));
			})
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}


function queryPropertyTypeByCategory3(){
	var params={
		category3Id:$('#category3Select').attr('value')
	};
	
	//set data to modify textfield
	$("#category3NameModify").val($('#category3Select').getSelectedText());
	
	$.ajax({
		type:"POST",
		url:"categoryAjax_queryPropertyTypeByCategory3.action",
		dataType:"json",
		data:params,
		success:function(msg){
			$('#propertyTypeSelect').get(0).options.length=0;
			$('#propertyValueSelect').get(0).options.length=0;
			
			var data = eval("("+msg+")"); 
			$.each(data,function(index,data){
				var typeId = data.id;
				var typeName = data.typeName;
				$('#propertyTypeSelect').get(0).options.add(new Option(typeName,typeId));
			})
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}



function queryPropValueByPropType(){
	var params={
		propertyTypeId:$('#propertyTypeSelect').attr('value')
	};
	$("#propertyTypeNameModify").val($('#propertyTypeSelect').getSelectedText());
	$.ajax({
		type:"POST",
		url:"categoryAjax_queryPropValueByPropType.action",
		dataType:"json",
		data:params,
		success:function(msg){
			$('#propertyValueSelect').get(0).options.length=0;
			var data = eval("("+msg+")"); 
			$.each(data,function(index,data){
				var valueId = data.id;
				var valueName = data.valueName;
				$('#propertyValueSelect').get(0).options.add(new Option(valueName,valueId));
			})
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
	
	
}

function onChangePropValueSelect(){
	//set data to modify textfield
	$("#propertyValueNameModify").val($('#propertyValueSelect').getSelectedText());
}

/**
 * 删除选中项
 */
function confirmDel(){
	if(confirm("级联删除且删除后无法恢复，确认删除吗？")){
		return true;
	}
	return false;
}
function delCategory1(){
	//are you sure?
	if(!confirmDel()){return ;};
	
	//sure
	$.ajax({
		type:"POST",
		url:"categoryAjax_delCategory1.action",
		dataType:"json",
		data:{category1Id:$('#category1Select').attr('value')},
		success:function(msg){
			var data = eval("("+msg+")"); 
			if(data.responseCode==0){
				alert(data.responseContent);
				return;
			}
			//delete selected data
			$('#category1Select').removeSelected();
			
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}

function delCategory2(){
	//are you sure?
	if(!confirmDel()){return ;};
	
	//sure
	$.ajax({
		type:"POST",
		url:"categoryAjax_delCategory2.action",
		dataType:"json",
		data:{category2Id:$('#category2Select').attr('value')},
		success:function(msg){
			var data = eval("("+msg+")"); 
			if(data.responseCode==0){
				alert(data.responseContent);
				return;
			}
			//delete selected data
			$('#category2Select').removeSelected();
			
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
	
}

function delCategory3(){
	//are you sure?
	if(!confirmDel()){return ;};
	
	//sure
	$.ajax({
		type:"POST",
		url:"categoryAjax_delCategory3.action",
		dataType:"json",
		data:{category3Id:$('#category3Select').attr('value')},
		success:function(msg){
			var data = eval("("+msg+")"); 
			if(data.responseCode==0){
				alert(data.responseContent);
				return;
			}
			//delete selected data
			$('#category3Select').removeSelected();
			
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
	
}
function delPropertyType(){
	//are you sure?
	if(!confirmDel()){return ;};
	
	//sure
	$.ajax({
		type:"POST",
		url:"categoryAjax_delPropertyType.action",
		dataType:"json",
		data:{propertyTypeId:$('#propertyTypeSelect').attr('value')},
		success:function(msg){
			var data = eval("("+msg+")"); 
			if(data.responseCode==0){
				alert(data.responseContent);
				return;
			}
			//delete selected data
			$('#propertyTypeSelect').removeSelected();
			
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
	
	
}
function delPropertyValue(){
	//are you sure?
	if(!confirmDel()){return ;};
	
	//sure
	$.ajax({
		type:"POST",
		url:"categoryAjax_delPropertyValue.action",
		dataType:"json",
		data:{propertyValueId:$('#propertyValueSelect').attr('value')},
		success:function(msg){
			var data = eval("("+msg+")"); 
			if(data.responseCode==0){
				alert(data.responseContent);
				return;
			}
			//delete selected data
			$('#propertyValueSelect').removeSelected();
			
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
	
}



/**
 * 修改类别和属性名称
 * @return
 */
function modifyCategory1Name(){
	var category1NameModify = $("#category1NameModify").val();
	var category1Id = $("#category1Select").attr('value');
	var pageShow = 0;
	if($("#check_modifyCategory1Id").attr("checked")){
		pageShow = 1;
	};

	$.ajax({
		type:"POST",
		url:"categoryAjax_modifyCategory1Name.action",
		dataType:"json",
		data:{category1Id:category1Id,category1NameModify:category1NameModify,pageShow:pageShow},
		success:function(msg){
			var data = eval("("+msg+")"); 
			if(data.responseCode==0){
				alert(data.responseContent);
				return;
			}
			alert(data.responseContent);
			//modify selected data
			$($("#category1Select option")[$("#category1Select").getSelectedIndex()]).text($("#category1NameModify").val());
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}
function modifyCategory2Name(){
	var category2NameModify = $("#category2NameModify").val();
	var category2Id = $("#category2Select").attr('value');
	var pageShow = 0;
	if($("#check_modifyCategory2Id").attr("checked")){
		pageShow = 1;
	};
	$.ajax({
		type:"POST",
		url:"categoryAjax_modifyCategory2Name.action",
		dataType:"json",
		data:{category2Id:category2Id,category2NameModify:category2NameModify,pageShow:pageShow},
		success:function(msg){
			var data = eval("("+msg+")"); 
			if(data.responseCode==0){
				alert(data.responseContent);
				return;
			}
			alert(data.responseContent);
			//modify selected data
			$($("#category2Select option")[$("#category2Select").getSelectedIndex()]).text($("#category2NameModify").val());
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}
function modifyCategory3Name(){
	var category3NameModify = $("#category3NameModify").val();
	var category3Id = $("#category3Select").attr('value');
	$.ajax({
		type:"POST",
		url:"categoryAjax_modifyCategory3Name.action",
		dataType:"json",
		data:{category3Id:category3Id,category3NameModify:category3NameModify},
		success:function(msg){
			var data = eval("("+msg+")"); 
			if(data.responseCode==0){
				alert(data.responseContent);
				return;
			}
			alert(data.responseContent);
			//modify selected data
			$($("#category3Select option")[$("#category3Select").getSelectedIndex()]).text($("#category3NameModify").val());
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}
function modifyPropertyTypeName(){
	var propertyTypeNameModify = $("#propertyTypeNameModify").val();
	var propertyTypeId = $("#propertyTypeSelect").attr('value');
	$.ajax({
		type:"POST",
		url:"categoryAjax_modifyPropertyTypeName.action",
		dataType:"json",
		data:{propertyTypeId:propertyTypeId,propertyTypeNameModify:propertyTypeNameModify},
		success:function(msg){
			var data = eval("("+msg+")"); 
			if(data.responseCode==0){
				alert(data.responseContent);
				return;
			}
			alert(data.responseContent);
			//modify selected data
			$($("#propertyTypeSelect option")[$("#propertyTypeSelect").getSelectedIndex()]).text($("#propertyTypeNameModify").val());
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}
function modifyPropertyValueName(){
	var propertyValueNameModify = $("#propertyValueNameModify").val();
	var propertyValueId = $("#propertyValueSelect").attr('value');
	$.ajax({
		type:"POST",
		url:"categoryAjax_modifyPropertyValueName.action",
		dataType:"json",
		data:{propertyValueId:propertyValueId,propertyValueNameModify:propertyValueNameModify},
		success:function(msg){
			var data = eval("("+msg+")"); 
			if(data.responseCode==0){
				alert(data.responseContent);
				return;
			}
			alert(data.responseContent);
			//modify selected data
			$($("#propertyValueSelect option")[$("#propertyValueSelect").getSelectedIndex()]).text($("#propertyValueNameModify").val());
		},
		error:function(er){
			//alert(er.responseText);
			alert('系统出错')
		}
	})
}



